<%@ page contentType="text/html;charset=UTF-8" %>

<html>
<head>
	<title>栏目管理</title>
    <%@ include file="/common/import.jsp" %>
	<%@ include file="/common/meta.jsp" %>
    <script src="${ctx}/js/easyui/extendvalidate.js"></script>
		
		<script>
		$(function(){
			$('#channelList').treegrid({
				title:'栏目列表',
				iconCls:'icon-ok',
				fitColumns: true,
				nowrap: false,
				rownumbers: true,
				animate:true,
				collapsible:false,
				
				url:'${ctx}/wcm/channel/list!data.action?id=${id}',
				idField:'channelId',
				treeField:'channelName',				
				frozenColumns:[[
	                {title:'栏目名称',field:'channelName',width:150,
		                formatter:function(value){
		                	return '<span style="color:blue">'+value+'</span>';
		                }
	                }
				]],
				columns:[[
					{field:'codeName',title:'栏目标识',width:100,sortable:true,
						sorter:function(a,b){
							return (a>b?1:-1);
						}
					},
					{field:'displayName',title:'显示名称',width:120},
					{field:'isNavigation',title:'是否航行',width:80,
						formatter:function(value){
							if("1"==value){
								return "是";
							}else{
								return '否';
							}
						}
					},					
		           /*  {field:'isPushed',title:'是否已发布',width:150,
						formatter:function(value){
							if("1"==value){
								return "是";
							}else{
								return '否';
							}
						}
					},*/
					{field:'status',title:'当前状态',width:80,
						formatter:function(value){
		                	if( value=='1'){
								return '<font color=blue>启用</font>';
							}else{ 
								return '<font color=red>停用</font>';
							}
		                }
		             }
					
				]],
				toolbar:[					
		          {		        	  
		              	text:'增加栏目',
			              iconCls:'icon-add',
			              handler:function(){addRootChannel();}
		        	  
		          },'-',
		           {		        	  
		              	text:'增加子栏目',
			              iconCls:'icon-add',
			              handler:function(){addSubChannel();}
		          } ,'-',
		          {
		              text:'删除',
		              iconCls:'icon-cut',
		              handler:function(){deleteChannel();}	             
		          },'-',	          
		          {
		              text:'修改',
		              iconCls:'icon-edit',
		              handler:function(){editChannel();}
		          }
		          ,'-',	
		           {
		              text:'刷新',
		              iconCls:'icon-reload',
		              handler:function(){
		                  reload();
		             }
		          },'-',
		          {
		              text:'栏目下稿件管理',
		              iconCls:'icon-add',
		              handler:function(){		              	
		              	manuscriptList();
		             }
		          }
		        ],
				onBeforeLoad:function(row,param){
					if (row){
						$(this).treegrid('options').url = 'list!data.action?parentId=';
					} 
				},
				onDblClickRow:function(row){
					editChannel();
				}
			});
		});	

		var widthcount = $(document.body).width()-20; 
		var leftcount = document.documentElement.scrollLeft;
		
		function addRootChannel(paraFlag){
			$('#channelAddFrame').html('');			
			var url = '${ctx}/wcm/channel/add.action?parentId=0';							
			$('#channelAddFrame').attr("src",url);			
			$('#channelAddWin').window('open');	
		}
		
		function addSubChannel(paraFlag){
			$('#channelAddFrame').html('');
			var node = getSelected();		
			if (node){			
				var url = '${ctx}/wcm/channel/add.action?parentId='+node.channelId ;
				$('#channelAddFrame').attr("src",url);			
				$('#channelAddWin').window('open');
			}	
		}
		
		function editChannel(){
			var node = getSelected();		
			if (node){	
				var url = '${ctx}/wcm/channel/add.action?channelId='+node.channelId;
				$('#channelAddFrame').attr("src",url);			
				$('#channelAddWin').window('open');	
			}
		}
		
		function manuscriptList(){
			var node = getSelected();
			if(node){
				var orgId = node.channelId;
				var deptListUrl = '${ctx}/wcm/manuscript/list.action?toPage=artice&channelId='+orgId;
				if ($.isFunction(window.parent.addTab)){
				    window.parent.addTab('栏目管理['+node.channelName+']',deptListUrl,'icon-dept');
				}else{
					/**
					$('#channelDeptWin').css({"width":widthcount,"height":"450px","left":leftcount});
					$('#channelDeptFrame').attr("src",deptListUrl);
					$('#channelDeptWin').panel('setTitle',"栏目管理["+node.channelName+"]");
					$('#channelDeptWin').window('open');
					**/
					parent.openPage("栏目管理["+node.channelName+"]",deptListUrl,"1200","680");
				}
			}
		}

		//删除
		function deleteChannel(){					
			var node = getSelected();	
			if(node){
		       $.messager.confirm('确认','您确定要删除:<font color="red">'+node.channelName+'</font> ？',function(r){
		          if(r){
						$.ajax({
								type: "post",
								url: "${ctx}/wcm/channel/del.action?id="+node.channelId,
								success: function(data, textStatus){
									var result = jQuery.parseJSON(data);
							    	if(result.flag=='T'){
							    		$.messager.alert('提交结果', '操作成功', 'info',function(){
							    		    $('#channelList').treegrid('remove', node.channelId);
							    		    if("0"==node.parentId){
							    		    	reload();
							    		    }else{
							    		  		reloadTree(node.parentId,'');
							    		    }
							    		});
							    	}else{
							    		$.messager.alert('提交结果', result.msg, 'error');
							    	}      
								}
							});
		          }
		       });		             		
		    }	
		}
		
		function getSelected(){
			var selected = $('#channelList').treegrid('getSelected');
			if (selected){
				return selected;
			}else{
				$.messager.alert('提示', '请选择要操作的数据', 'info');
			}
		}
		//刷新
		function reload(){
				var node = $('#channelList').treegrid('getSelected');
				if (node && node.parentId !="0"){
					$('#channelList').treegrid('reload', node.channelId);				
				} else {
					$('#channelList').treegrid('reload');
				}		
		}
		//刷新树
		function reloadTree(fatherId,nodeId){
			if(nodeId==""){
				var parent = $('#channelList').treegrid('getParent',fatherId);
				if(parent){
					var parentId = parent["channelId"]; 
					$('#channelList').treegrid('reload', parentId);
				}else{
					$('#channelList').treegrid('reload');
				}
			}else{
				$('#channelList').treegrid('reload', fatherId);
			}
		}
		
		function closeChannelAddWindow(){
			$("#channelAddWin").window("close");
		}
		function closeChannelDeptWin(){
			$("#channelDeptWin").window("close");
		}
		function closeOrgWindow(){
			$("#channelAddWin").window("close");
		}
	</script>
</head>

<body>
	<table id="channelList"></table>

	<div id="channelAddWin" class="easyui-window" title="栏目信息" style="padding:5px;top:10px; width:90%;height:630px;overflow: hidden;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
   	 <iframe frameborder="0" id="channelAddFrame" height="100%" width="100%" scrolling="yes" frameborder="0" ></iframe>
    </div>

	<div id="channelDeptWin" class="easyui-window" title="栏目弹出信息" style="padding:5px;float:left;top:10px;overflow: hidden;" iconCls="icon-search" closed="true" minimizable="false" maximizable="false" maximized="true" collapsible="false">
   	 <iframe frameborder="0" id="channelDeptFrame" height="100%" width="100%" scrolling="yes" frameborder="0" ></iframe>
    </div>
</body>
    <script type="text/javascript" src="${ctx}/js/uct/uct_form.js"></script>
    <script type="text/javascript" src="${ctx}/js/uct/date.js"></script>
</html>